package com.boang.buffer;

/*
  @author: 13813
  @date: 2024/11/21 16:03
*/
public class StringBufferDemo {
    public static void main(String[] args) {
        /*
            字符串缓冲区
            byte[] value;
         */

        //初始容量为 16 个字符
        StringBuffer stringBuffer = new StringBuffer();
        //添加
        m1(stringBuffer);
        //删除
//        m2(stringBuffer);
        //改
//        m3(stringBuffer);
        //查
//        m4(stringBuffer);
    }

    private static void m4(StringBuffer stringBuffer) {
        System.out.println(stringBuffer.indexOf("a"));
        System.out.println(stringBuffer.toString());
    }

    private static void m3(StringBuffer stringBuffer) {
        stringBuffer.setCharAt(1,'W');
    }

    private static void m2(StringBuffer stringBuffer) {
        //删除(包括开始，不包括结尾)
        stringBuffer.delete(1, 3);
    }

    private static void m1(StringBuffer stringBuffer) {
        stringBuffer.append("a");
        stringBuffer.append("b");
        stringBuffer.append("c");
        stringBuffer.append("d");
    }
}
